package com.itcast.clientx.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itcast.clientx.bean.Maven;
import com.itcast.clientx.bean.Repository;
import com.itcast.clientx.mapper.MavenMapper;
import com.itcast.clientx.mapper.RepositoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RepositoryService {
    @Autowired
    private RepositoryMapper mapper;
    @Autowired
    private MavenMapper mapper_;
    @Transactional
    public Boolean insert(Repository repository, List<Maven> list){
        QueryWrapper<Repository> wrapper = new QueryWrapper<>();
        wrapper.eq("groupid",repository.getGroupid());
        wrapper.eq("artifactid",repository.getArtifactid());
        Repository r = mapper.selectOne(wrapper);
        if(r!=null){
            return false;
        }
        int i = mapper.insert(repository);
        i = repository.getId();
        for (Maven mvn : list) {
            mvn.setRepositoryid(i);
            mapper_.insert(mvn);
        }
        return true;
    }
}
